<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container{
            display: flex;
        }
        .ball{
            width:150px;
            height: 150px;
            border:1px solid #ccc;
            border-radius: 100%;
           
        }
    </style>
    <script>
        function doOver(n){
            var divs=document.querySelectorAll(".ball");//集合
            var p=document.getElementById("txt");
            for(var i=0;i<=n;i++){
                divs[i].style.background="red";
            }
            p.innerHTML="这是第"+(n+1)+"个球";
            
        }

        function doOut(){
            var divs=document.querySelectorAll(".ball");//集合
            var p=document.getElementById("txt");
            for(var i=0;i<=4;i++){
                divs[i].style.background="white";
            }
            p.innerHTML="";

        }
    </script>
</head>
<body>
    <div class="container">
        <div class="ball" onmouseover="doOver(0)" onmouseout="doOut()"></div>
        <div class="ball" onmouseover="doOver(1)" onmouseout="doOut()"></div>
        <div class="ball" onmouseover="doOver(2)" onmouseout="doOut()"></div>
        <div class="ball" onmouseover="doOver(3)" onmouseout="doOut()"></div>
        <div class="ball" onmouseover="doOver(4)" onmouseout="doOut()"></div>
    </div>
    <p id="txt"></p>
</body>
</html>